import Mock from 'mockjs'


// 获取Random对象
const Random = Mock.Random;

// 示例：使用mockjs模拟数据
Mock.mock('/api/data', (req, res) => {
    let list = [];
    for (let i = 0; i < 30; ++i) {
        let obj = {
            title: Random.csentence(5, 10),     // 随机一段文本
            company: Random.csentence(5, 10),
            number: Random.integer(100, 10000),  // 随机一个数字
            image: Random.image('200x300', '#5fb878', '#fff', 'This is a image')
        }
        list.push(obj);
    }
    return {
        code: 200,
        msg: '请求成功！',
        data: list
    }
});



/**
 * 用户登录
 * - API: '/user/login'
 * - Content-Type: 'application-x-www-urlencoed'
 * - Params: account: 账号, password: 密码
 */
Mock.mock('/user/login', 'post', (req, res) => {

    console.log("请求：");
    console.log(req);
    console.log("响应：");
    console.log(res);


    return {
        code: 200,
        msg: 'ok',
        data: {
            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiYWRtaW4iLCJhdmF0YXIiOiIiLCJleHAiOjE2MDQxMzIzOTUsInVzZXJJZCI6IjkiLCJ1c2VybmFtZSI6InhzaXJsIn0.b6O3HhTKpVnOrSd-EfN4XVJ0mDAs92am75tcGYnxvKU'
        }
    }
})

/**
 * 获取文章
 * - API: '/article/list'
 * - Content-Type: 'application/json'
 * - Params: { current: 当前页, size: 每页记录数, order: 排序方式 }
 */
Mock.mock('/article/list', 'get', (req, res) => {
    return {
        code: 200,
        msg: 'ok',
        data: {
            records: [],
            total: 10
        }
    }
})